﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading.Tasks;

namespace JNPF.Data
{
    /// <summary>
    /// 操作接口
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2017.03.03
    /// </summary>
    public interface IDatabaseExt : ITransaction, IDisposable
    {
        /// <summary>
        /// 使用Bulk批量导入,速度快
        /// </summary>
        /// <param name="dt">集合</param>
        /// <returns></returns>
        int BulkInsert(DataTable dt);

        /// <summary>
        /// 执行语句
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数</param>
        int ExecuteSql(string sql, DbParameter[] param = null);

        /// <summary>
        /// 执行语句
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数</param>
        Task<int> ExecuteSqlAsync(string sql, DbParameter[] param = null);

        /// <summary>
        /// 执行语句
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数</param>
        object ExecuteScalar(string sql, DbParameter[] param = null);

        /// <summary>
        /// 执行语句
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数</param>
        Task<object> ExecuteScalarAsync(string sql, DbParameter[] param = null);

        /// <summary>
        /// 通过SQL获取List
        /// </summary>
        /// <typeparam name="T">实体泛型</typeparam>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">SQL参数</param>
        /// <returns></returns>
        List<T> GetListSql<T>(string sql, DbParameter[] param = null) where T : class, new();

        /// <summary>
        /// 通过SQL获取List
        /// </summary>
        /// <typeparam name="T">实体泛型</typeparam>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">SQL参数</param>
        /// <returns></returns>
        Task<List<T>> GetListSqlAsync<T>(string sql, DbParameter[] param = null) where T : class, new();

        /// <summary>
        /// 通过SQL获取DataTable
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">SQL参数</param>
        /// <returns></returns>
        DataTable GetTableSql(string sql, DbParameter[] param = null);

        /// <summary>
        /// 通过SQL获取DataTable
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">SQL参数</param>
        /// <returns></returns>
        Task<DataTable> GetTableSqlAsync(string sql, DbParameter[] param = null);


        /// <summary>
        /// 通过SQL获取DataTable
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">SQL参数</param>
        /// <returns></returns>
        Task<DataTable> GetTableSqlByUnconvertAsync(string v, DbParameter[] dbParameters);

        Task<List<Dictionary<string, object>>> GetPageDictionaryAsync(string sql, DbParameter[] param = null);
    }
}
